<!DOCTYPE html>
<html  xmlns:th="http://www.thymeleaf.org">
<html lang="en">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Star Admin Premium Bootstrap Admin Dashboard Template</title>
    <!-- plugins:css -->
<!--    <link rel="stylesheet" href="../css/bootstrap.css">-->
    <link rel="stylesheet" href="../assets/vendors/iconfonts/mdi/css/materialdesignicons.min.css">
    <link rel="stylesheet" href="../assets/vendors/iconfonts/ionicons/dist/css/ionicons.css">
    <link rel="stylesheet" href="../assets/vendors/iconfonts/flag-icon-css/css/flag-icon.min.css">
    <link rel="stylesheet" href="../assets/vendors/css/vendor.bundle.base.css">
    <link rel="stylesheet" href="../assets/vendors/css/vendor.bundle.addons.css">
    <link rel="stylesheet" href="../assets/css/shared/style.css">
    <link rel="stylesheet" href="../assets/css/demo_1/style.css">
    <link rel="shortcut icon" href="../assets/images/favicon.ico" />
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>

</head>
<body>
<div class="container-scroller">
    <nav class="navbar default-layout col-lg-12 col-12 p-0 fixed-top d-flex flex-row">
        <div class="text-center navbar-brand-wrapper d-flex align-items-top justify-content-center">
            <a class="navbar-brand brand-logo" href="index.html">
                <img src="../assets/images/logo.png" alt="logo"> </a>
        </div>
        <div class="navbar-menu-wrapper d-flex align-items-center">
            <ul class="navbar-nav">
                <li class="nav-item font-weight-semibold d-none d-lg-block">帮助 : +123 4567 8910</li>
                <li class="nav-item font-weight-semibold d-none d-lg-block">欢迎来到电力设备管理系统</li>
            </ul>
            <form class="ml-auto search-form d-none d-md-block" action="#">
                <div class="form-group">
                    <input type="search" class="form-control" placeholder="Search Here">
                </div>
            </form>
            <ul class="navbar-nav ml-auto">
                <li class="nav-item dropdown">
                    <span><a class="nav-link count-indicator"  href="/logout"  aria-expanded="false">
                        <i class="mdi mdi-bell-outline"></i>退出
                    </a></span>
                </li>
                <li class="nav-item dropdown d-none d-xl-inline-block user-dropdown">
                    <img class="img-xs rounded-circle" src="../assets/images/faces/face8.jpg" alt="Profile image">
                    <span th:text="${username}"></span>
                </li>
            </ul>
        </div>
    </nav>
    <div class="container-fluid page-body-wrapper">
        <nav class="sidebar sidebar-offcanvas" id="sidebar">
            <ul class="nav">
                <li class="nav-item nav-profile">
                    <a href="#" class="nav-link">
                        <div class="profile-image">
                            <img class="img-xs rounded-circle" src="../assets/images/faces/face8.jpg" alt="profile image">
                            <div class="dot-indicator bg-success"></div>
                        </div>
                        <div class="text-wrapper">
                            <span th:text="${username}"></span>
                            <p class="designation">当前用户</p>
                        </div>
                    </a>
                </li>
                <li class="nav-item nav-category">主菜单</li>
                <li class="nav-item">
                    <a class="nav-link" href="/main">
                        <i class="menu-icon typcn typcn-document-text"></i>
                        <span class="menu-title">首页</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/devices/devicesList">
                        <i class="menu-icon typcn typcn-document-text"></i>
                        <span class="menu-title">设备管理</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/suppliers/suppliersList">
                        <i class="menu-icon typcn typcn-document-text"></i>
                        <span class="menu-title">供应商管理</span>
                    </a>
                </li>
            </ul>
        </nav>
        <div class="main-panel">
            <div class="content-wrapper">
                <button  class="btn btn-success">
                    <a  data-toggle="modal" data-target="#modalAdd">新增</a>
                </button>
                <table class="table table-bordered">
                    <thead>
                    <th>序号</th>
                    <th>商品名</th>
                    <th>价格</th>
                    <th>数量</th>
                    <th>种类</th>
                    <th>供应商</th>
                    <th>管理</th>
                    </thead>
                    <tbody>
                    <tr th:each="devices:${data}">
                        <td th:text="${devices.getId()}"></td>
                        <td th:text="${devices.name}"></td>
                        <td th:text="${devices.getPrice()}"></td>
                        <td th:text="${devices.getQuantity()}"></td>
                        <td th:text="${devices.getCategory()}"></td>
                        <td th:text="${devices.getSupplier()}"></td>
                        <td>
                            <button class="btn btn-danger"  th:onclick="del([[${devices.getId()}]])">删除</button>
                            <button data-toggle="modal" data-target="#modalUpdate" class="btn btn-success"
                                    th:onclick="update([[${devices.getId()}]],[[${devices.name}]],[[${devices.getPrice()}]],[[${devices.getQuantity()}]],[[${devices.getCategory()}]],[[${devices.getSupplier()}]])">更新</button>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
            <footer class="footer">
                <div class="container-fluid clearfix">
                    <span class="text-muted d-block text-center text-sm-left d-sm-inline-block">Copyright © 21106225刘芸</span>
                    <span class="float-none float-sm-right d-block mt-1 mt-sm-0 text-center"> Free <a href="https://www.bootstrapdash.com/bootstrap-admin-template/" target="_blank">Bootstrap admin templates</a> from Bootstrapdash.com</span>
                </div>
            </footer>
        </div>
    </div>
    <!-- 新增模态框（Modal） -->
    <div class="modal fade" id="modalAdd" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        &times;
                    </button>
                    <h4 class="modal-title" id="myModalLabel">
                        新增商品
                    </h4>
                </div>
                <div class="modal-body">
                    <form action="/devices/devicesAddProcess" method="post">
                        <div class="form-control">
                            <label for="">商品名</label>
                            <input type="text" name="name" id="">
                        </div>
                        <div class="form-control">
                            <label for="">商品价格</label>
                            <input type="text" name="price" id="">
                        </div>
                        <div class="form-control">
                            <label for="">数量</label>
                            <input type="text" name="quantity" id="">
                        </div>
                        <div class="form-control">
                            <label for="">种类</label>
                            <input type="text" name="category" id="">
                        </div>
                        <div class="form-control">
                            <label for="">供应商</label>
                            <input type="text" name="supplier" id="">
                        </div>
                        <div class="form-control">
                            <input type="submit" value="提交" class="btn btn-primary">
                        </div>
                    </form>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>
    <!--更新模态窗-->
    <!-- 模态框（Modal） -->
    <div class="modal fade" id="modalUpdate" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h4 class="modal-title" id="myModalLabel">更新商品</h4>
                </div>
                <div class="modal-body">
                    <div class="form-control">
                        <label for="">序号</label>
                        <input type="text" name="id" id="Id" disabled="disabled">
                    </div>
                    <div class="form-control">
                        <label for="">商品名</label>
                        <input type="text" name="name" id="name">
                    </div>
                    <div class="form-control">
                        <label for="">商品价格</label>
                        <input type="text" name="price" id="price">
                    </div>
                    <div class="form-control">
                        <label for="">数量</label>
                        <input type="text" name="quantity" id="quantity">
                    </div>
                    <div class="form-control">
                        <label for="">种类</label>
                        <input type="text" name="category" id="category">
                    </div>
                    <div class="form-control">
                        <label for="">供应商</label>
                        <input type="text" name="supplier" id="supplier">
                    </div>
                    <div class="form-control">
                        <!--                        <input type="submit" value="更改" class="btn btn-warning">-->
                        <button class="btn btn-warning" id="btnUpdate">更新</button>
                    </div>
                </div>

            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div>
    <!-- /.modal -->
</div>
</body>
</html>
<script src="../js/jquery.js"></script>
<!--<script src="../js/bootstrap.js"></script>-->
<script src="../assets/vendors/js/vendor.bundle.base.js"></script>
<script src="../assets/vendors/js/vendor.bundle.addons.js"></script>
<script src="../assets/js/shared/off-canvas.js"></script>
<script src="../assets/js/shared/misc.js"></script>
<script src="../assets/js/demo_1/dashboard.js"></script>
<!--<script src="../assets/js/shared/jquery.cookie.js" type="text/javascript"></script>-->
<script>
    function del(id){
        alert(id)
        //     jquery的post方法ajax方法
        $.post("/api/devicesDelete",{"id":id},function(res){
            console.log(res)
            if(res==1){
                alert("删除成功！");
                location.reload();
            }else{
                alert("删除失败!");
                location.reload();
            }
        })
    }
    function update(id,name,price,quantity,category,supplier){
        // var flag = confirm("是否更新该条记录？");
        // if (flag==true){
        //     location.href="/devices/devicesUpdate?id="+id;
        // }
        console.log(id)
        $('#Id').val(id)
        $('#name').val(name)
        $('#price').val(price)
        $('#quantity').val(quantity)
        $('#category').val(category)
        $('#supplier').val(supplier)
    }
    $('#btnUpdate').click(function (){
        var flag=confirm("确认提交更新？");
        console.log($('#name').val())
        if(flag==true){
            $.post("/api/devicesUpdateProcess",{"Id":$('#Id').val(),"name":$('#name').val(),"price":$('#price').val(),
                "quantity":$('#quantity').val(),"category":$('#category').val(),"supplier":$('#supplier').val()
            },function (res) {
                if(res==1){
                    alert("更新成功！");
                    location.reload();
                }else{
                    alert("更新失败!");
                    location.reload();
                }
            })
        }
    })
</script>
